<%@page import="GestioneOrdine.Ordine"%>
<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.Vector"%>
<%@ page import="java.util.HashMap"%>
<%@page import="GestioneComponente.Componente"%>
<%@page import="GestioneComponente.Caratteristiche"%>
<%@page import="java.util.Map.Entry"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Elaborazione Ordine</title>
<link href="../css/bootstrap.min.css" rel="stylesheet" media="screen">
<script src="../js/jquery-1.11.1.min.js"></script>
<script src="../js/inserimentoCaratteristiche.js"></script>
<script src="../js/GestioneCookie.js"></script>
<link href="../css/indexBootCSS.css" rel="stylesheet" type="text/css">
<style>
.Nome {
	width: 50%;
	float: left;
	height: 30px;
}

.Descrizione {
	width: 50%;
	float: left;
	height: 30px;
}
</style>
</head>
<body>
	<jsp:useBean id="ordine" scope="session" class="GestioneOrdine.Ordine" />
	<jsp:useBean id="assemblaggio" scope="session" class="GestioneAssemblaggio.Assemblaggio" />
	<jsp:useBean id="database" scope="page" class="GestioneDB.ConnessioneDB" />
	<jsp:useBean id="utente" scope="session" class="GestioneUtente.Utente" />
	<div class="row affix-row">
		<div class="col-sm-3 col-md-2 affix-sidebar">
			<div class="sidebar-nav">
				<div class="navbar navbar-default" role="navigation">
					<div class="navbar-header">
						<button type="button" class="navbar-toggle" data-toggle="collapse"
							data-target=".sidebar-navbar-collapse">
							<span class="sr-only">Toggle navigation</span> <span
								class="icon-bar"></span> <span class="icon-bar"></span> <span
								class="icon-bar"></span>
						</button>
						<span class="visible-xs navbar-brand">Sidebar menu</span>
					</div>
					<div class="navbar-collapse collapse sidebar-navbar-collapse">
						<ul class="nav navbar-nav" id="sidenav01">
							<li class="active"><a href="indexBoot.html"
								data-toggle="collapse" data-target="#toggleDemo0"
								data-parent="#sidenav01" class="collapsed">
									<div>
										<img src="logo.jpg" alt="logo">
									</div>
							</a></li>

							<li><a href="indexBoot.html"> <span
									class="glyphicon glyphicon-home"></span> HomePage
							</a></li>

							<li><a href="ChiSiamo.html" class="collapsed"> <span
									class="glyphicon glyphicon-inbox"></span> Chi Siamo
							</a></li>

							<li>
								<!-- sottomenu --> <a href="#" data-toggle="collapse"
								data-target="#toggleDemo" data-parent="#sidenav01"
								class="collapsed"> <span class="glyphicon glyphicon-wrench"></span>
									Assemblaggio <span class="caret pull-right"></span>
							</a>
								<div class="collapse" id="toggleDemo" style="height: 0px;">
									<ul class="nav nav-list">
										<li><a href="Automatico.html">Automatico</a></li>
										<li><a href="ManualeAssistito.html">Manuale Assistito</a></li>
									</ul>
								</div>
							</li>

							<li><a href="Contatti.html"><span
									class="glyphicon glyphicon-phone"></span> Contatti</a></li>
							<li><a href="Login.html"><span
									class="glyphicon glyphicon-user"></span> Login</a></li>
						</ul>
					</div>
					<!--/.nav-collapse -->
				</div>
			</div>
		</div>
		<div class="col-sm-9 col-md-10 affix-content">
			<div class="container">

				<div class="page-header">
					<div id="logged">
						<table id="logged">
							<tr id="info">
								<td id="user"></td>
								<td id="pagina_personale"></td>
								<td id="logout"></td>
							</tr>
						</table>
					</div>
					<h3>
						<script>
							document.write(document.title)
						</script>
					</h3>
				</div>
				<div id="principale">
					<%
						ordine.instanziaLista();
						if (utente.getId() == null) {
							out.println("<script>alert('Devi essere loggato per poter completare la procedura ');document.location.href='Login.html?l=1';</script>");
						} 
						else {
							for (Componente i : assemblaggio.getPezziScelti()) {
								i.setDati(i.getIdProdotto());
							}
							Date data_oggi = new Date();
							ordine.setIdordine(ordine.generaIdOrdine());
							ordine.setIdutente(utente.getId());
							ordine.setPagato(false);
							ordine.setStato("IN ACCETTAZIONE");
							for (Componente i : assemblaggio.getPezziScelti()) {
								ordine.aggiungiProdotto(i.getIdProdotto(), 1);
								ordine.setDataordine(data_oggi);
							}
							//Ordine.inserisciOrdineDatabase(ordine);
						}
					%>
					<h1>
						Il tuo ordine
						</h1>
					<h1>I pezzi selezionati sono:</h1>
					<table>
						<%	
							float j=0;
							for (Componente i : assemblaggio.getPezziScelti()) {
						%>
						<tr class="Nome">
							<td><%=i.getProduttore()%> <%=i.getNome()%></td>
						</tr>
						<tr class="Descrizione">
							<td>
								&euro; <%=i.getPrezzo() %>
								<% j=j+i.getPrezzo(); %>
							</td>
						</tr>
						<%
							}
						%>
					<tr class="Nome"><td>Totale</td></tr>
					<tr class="Descrizione"><td>&euro; <%=j %></td></tr>
					</table>
					<input type="button" id="bottone" class="bottone" value="Conferma ordine"
							style="width: 15%">
					<input type="button" id="bottone2" class="bottone" value="Annulla ordine"
							style="width: 15%">
					<input type="button" id="bottone3" class="bottone" value="Indietro"
							style="width: 15%">
					<div id="result"></div>
					<script>
					$('#bottone').click(
							function() {
									$.ajax({
										url : 'ConfermaOrdine.jsp',
										type : 'POST',
										dataType : 'html',
										success : function(data) {
											$('#result').html(data);
											if($('#error').val()==1)
												alert("Ordine non inserito ");
											else{
												alert("Ordine inserito con successo");
												document.location.href = "PaginaPersonale.html";
											}
										}
									})
								})
					$('#bottone2').click(
							function() {
								$.ajax({
									url : 'ConfermaOrdine.jsp',
									type : 'POST',
									dataType : 'html',
									data:{
										annulla : "1"
									},
									success : function(data) {
										alert("Ordine annullato");
										document.location.href = "ManualeAssistito.html";
									}
								})
							})
					$('#bottone3').click(
							function() {
								document.location.href = "MStep12.html";
							})
					</script>
				</div>
			</div>
		</div>
	</div>
	<!-- JS -->
	<!-- <script src="//code.jquery.com/jquery.js"></script>-->

	<script src="../js/bootstrap.min.js"></script>
	<!-- JS -->
</body>
</html>